package club.jdiy.core.convert;

import club.jdiy.utils.DateUtils;

import java.time.*;
import java.util.Date;

class LocalDateConverter extends Converter {
    private final LocalDate source;

    public LocalDateConverter(LocalDate source) {
        this.source = source;
    }

    public LocalDateConverter(java.sql.Date source) {
        this.source = source.toLocalDate();
    }

    @Override
    public LocalDate getSource() {
        return source;
    }

    @Override
    public Long getLong() {
        return source.atStartOfDay().toInstant(ZoneOffset.ofHours(8)).toEpochMilli();
    }

    @Override
    public String getString() {
        return DateUtils.fmt_date.format(source);
    }

    @Override
    public Date getDate() {
        return Date.from(source.atStartOfDay().toInstant(ZoneOffset.ofHours(8)));
    }

    @Override
    public LocalDate getLocalDate() {
        return source;
    }

    @Override
    public LocalDateTime getLocalDateTime() {
        return source.atStartOfDay();
    }

}
